package com.wpp.util;

import java.util.List;

/**
 * @author by wpp25
 * @Classname PageUtil
 * @Description
 * @Date 2020/11/7 22:16
 */
public class PageUtil<T> {

    private Integer pageNum;
    /**
     * 每页条数
     */
    private Integer pageSize;
    /**
     * 总条数
     */
    private Integer totalSize;
    /**
     * 总页数 尾页
     */
    private Integer totalPage;

    private Boolean hasPrePage = false;
    private Integer prePage;

    private Boolean hasNextPage = false;
    private Integer nextPage;


    private List<T> pageData;

    public PageUtil(Integer pageNum, Integer pageSize, Integer totalSize, List<T> pageData) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
        this.pageData = pageData;
        this.totalPage = getTotalPage();

        if (pageNum > 1) {
            this.hasPrePage = true;
            this.prePage = this.pageNum - 1;
        }
        if (pageNum < this.totalPage) {
            this.hasNextPage = true;
            this.nextPage = this.pageNum + +1;
        }

    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(Integer totalSize) {
        this.totalSize = totalSize;
    }

    public Integer getTotalPage() {
        if (this.totalPage != null) {
            return this.totalPage;
        } else if (this.pageSize != null && this.totalSize != null) {
            this.totalPage = this.totalSize / this.pageSize;
            if (this.totalSize % this.pageSize > 0) {
                this.totalPage++;
            }
        }

        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Boolean getHasPrePage() {
        return hasPrePage;
    }

    public void setHasPrePage(Boolean hasPrePage) {
        this.hasPrePage = hasPrePage;
    }

    public Integer getPrePage() {
        return prePage;
    }

    public void setPrePage(Integer prePage) {
        this.prePage = prePage;
    }

    public Boolean getHasNextPage() {
        return hasNextPage;
    }

    public void setHasNextPage(Boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    public List<T> getPageData() {
        return pageData;
    }

    public void setPageData(List<T> pageData) {
        this.pageData = pageData;
    }

}
